package com.wft.面试题;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class 打印重复名字个总数 {
    public static void main(String[] args) {
        LinkedHashMap<String, Integer> collect = Stream.of(new Person(1, "张三", 28), new Person(2, "李四", 35), new Person(3, "张三", 28), new Person(4, "王五", 35),
                new Person(5, "张三", 28), new Person(6, "李四", 35), new Person(7, "赵六", 28), new Person(8, "田七", 35))
                .collect(Collectors.toMap(item -> item.getName(), item -> 1, (item1, item2) -> item1 + item2))
                .entrySet().stream().sorted((o1, o2) -> o2.getValue().compareTo(o1.getValue())).collect(Collectors.toMap(item -> item.getKey(), item -> item.getValue(), (item1, item2) -> item1, LinkedHashMap::new));
        for (String key : collect.keySet()) {
            System.out.println(key + " ==> " + collect.get(key));
        }
    }
}


class Person {
    private int id;
    private String name;
    private int age;

    public Person(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
